package com.smartcommunity.controller.village;

import com.smartcommunity.entity.people.dto.AddRealPowerDto;
import com.smartcommunity.bean.model.Result;
import com.smartcommunity.controller.BaseController;
import com.smartcommunity.entity.people.dto.UpdateRealPowerDto;
import com.smartcommunity.log.interceptor.Log;
import com.smartcommunity.service.village.RealPowerOrgService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @author heweiwei
 * @date 2018/7/16
 * 在线实有力量操作控制器
 */
@RestController
@RequestMapping(value = "/realPowerOrg")
@Api(value = "小区服务-实有力量相关",tags = "实有力量")
@Slf4j
public class RealPowerOrgController extends BaseController {
    @Autowired
    private RealPowerOrgService realPowerOrgService;

    @Log(info = "查询实有力量列表",module = "实有力量",function = "查询")
    @GetMapping(value = "/pageRealPower")
    @ApiOperation(value = "实有力量分页查询",notes = "实有力量分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "villageCode" ,value = "小区编号"),
            @ApiImplicitParam(name = "text" ,value = "关键字检索(身份证号码、姓名、手机号码)"),
            @ApiImplicitParam(name = "parentId" ,value = "行政区划ID"),
            @ApiImplicitParam(name = "labelIds" ,value = "标签ID集合，以逗号分隔"),
            @ApiImplicitParam(name = "labelName" ,value = "标签名称，支持模糊检索"),
            @ApiImplicitParam(name = "pageNumber" ,value = "页码",example = "1"),
            @ApiImplicitParam(name = "pageSize" ,value = "页数",example = "10")
    })
    public Result pageRealPower(@RequestParam(required = false, name = "villageCode") String villageCode,
                                @RequestParam(required = false, name = "text") String text,
                                @RequestParam(required = false, name = "parentId") String parentId,
                                @RequestParam(required = false, name = "labelIds") String labelIds,
                                @RequestParam(required = false, name = "labelName") String labelName,
                                @RequestParam(required = true, name = "pageNumber") String pageNumber,
                                @RequestParam(required = true, name = "pageSize") String pageSize){
        Map<String,Object> params = new HashMap<>(4);
        params.put("text",text);
        params.put("villageCode", villageCode);
        params.put("label", labelIds);
        params.put("labelName", labelName);
        return realPowerOrgService.queryRealPower(params,getPageNumber(pageNumber),getPageSize(pageSize));
    }

    @Log(info = "新增实有力量信息",module = "实有力量",function = "新增")
    @PostMapping("/insertRealPower")
    @ApiOperation(value = "新增实有力量",notes = "新增实有力量")
    public Result insertRealPower(@Valid @RequestBody @ApiParam(name = "addRealPowerDto", value = "实有力量对象") AddRealPowerDto addRealPowerDto)  {
        log.info("接口：insertRealPower；新增实有力量");
        return realPowerOrgService.insertRealPower(addRealPowerDto);
    }

    @Log(info = "删除实有力量信息",module = "实有力量",function = "删除")
    @DeleteMapping("/deleteRealPower")
    @ApiOperation(value = "删除实有力量",notes = "删除实有力量")
    public Result deleteRealPower(@RequestParam(required = true, name = "ids") String ids)  {
        log.info("接口：deleteRealPower；删除实有力量");
        return realPowerOrgService.deleteRealPower(ids);
    }

    @Log(info = "更新实有力量信息",module = "实有力量",function = "更新")
    @PostMapping("/updateRealPower")
    @ApiOperation(value = "更新实有力量",notes = "更新实有力量")
    public Result updateRealPower(@Valid @RequestBody @ApiParam(name = "updateRealPowerDto", value = "实有力量对象") UpdateRealPowerDto updateRealPowerDto)  {
        log.info("接口：updateRealPower；更新实有力量");
        return realPowerOrgService.updateRealPower(updateRealPowerDto);
    }

    @Log(info = "查询实有力量信息",module = "实有力量",function = "查询")
    @GetMapping("/getRealPower")
    @ApiOperation(value = "获取实有力量",notes = "获取实有力量")
    public Result getRealPower(@RequestParam(required = true, name = "id") String id)  {
        log.info("接口：getRealPower；获取实有力量");
        return realPowerOrgService.getRealPower(id);
    }

}
